package com.yonyou.brigade.openapi.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.ybz.service.IBriOrderNoteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RequestMapping("/note")
@Controller
public class NoteController {

    @Autowired
    @Qualifier("briOrderNoteServiceImpl")
    private IBriOrderNoteService briOrderNoteService;

    private static Logger logger = LoggerFactory.getLogger(NoteController.class);

    /**
     * 订单转记事（可传记事类型）
     * @param params
     * @param request
     * @return
     */
    @RequestMapping(value = "/convert",method = RequestMethod.POST)
    public @ResponseBody
    JSONArray convert(@RequestBody JSONArray params, HttpServletRequest request) {
        logger.info("/note/convert params：" + JSON.toJSONString(params));
        JSONArray result = briOrderNoteService.convert(params);
        return result;
    }

    @RequestMapping(value = "applyids",method = RequestMethod.POST)
    public @ResponseBody
    JSONObject getNotesByApplyIds(String tenantId, @RequestBody Map params) {
        logger.info("查询账本列表的参数：" + JSON.toJSONString(params));
        JSONObject noteInfosByApplyIds = briOrderNoteService.getNoteInfosByApplyIds(tenantId, params);
        logger.info("查询账本列表的返回：" + JSON.toJSONString(noteInfosByApplyIds));
        return noteInfosByApplyIds;
    }
}
